package com.paradogs.framework.core.netty.clients.common;

import com.paradogs.framework.core.netty.clients.master.MasterProperties;
import com.paradogs.framework.core.netty.clients.master.PRMasterClient;
import com.paradogs.framework.core.netty.server.ServerProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author: yumi
 * @date: 2023/11/27  15:25
 * @Description: TODO
 */
@Slf4j
@Component
public class PRClientLaunch implements ApplicationRunner {

    @Autowired
    private ServerProperties serverProperties;

    @Autowired
    private ClientsProperties clientsProperties;

    @Override
    public void run(ApplicationArguments args) throws Exception {

        // master
        if (!serverProperties.isMaster()) {
            PRMasterClient master = new PRMasterClient();
            master.start();
        }

        // common
        for (ClientsProperties.Client clientProperties : clientsProperties.clients) {
            PRServerClient client = new PRServerClient(clientProperties);
            client.start();
        }

    }
}
